from flask import Flask
import logging
from flask_socketio import SocketIO
# 初始化 SocketIO

logger = logging.getLogger(__name__)
from .decorator.ext_decorator import ext_decorator
socketio = SocketIO(cors_allowed_origins="*")
@ext_decorator
def init_websocket(app: Flask) -> None:
    # 在应用上下文中导入WebSocket处理器，避免循环导入
    with app.app_context():
        try:
            import apps.modules.main.views.chat_websocket
            import apps.modules.admin.views.cms.chat_websocket
            logger.info("WebSocket处理器导入成功")
        except Exception as e:
            logger.error(f"WebSocket处理器导入失败: {e}")

        # 初始化 SocketIO
        socketio.init_app(app, async_mode='threading')